package lg.minecraft.plugin.library.command;

import lg.minecraft.plugin.library.LGLibrary;
import lg.minecraft.plugin.library.input.InputType;
import lg.minecraft.plugin.library.input.PlayerInputManager;
import org.bukkit.entity.Player;

import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
public class InputCommand extends LGCommand {

    public InputCommand() {
        super(LGLibrary.getInstance(), "input");
    }

    @Override
    public CommandType getCommandType() {
        return CommandType.PLAYER;
    }

    @Override
    public void onCommand(CommandContext context) {
        Player player = context.getPlayer();
        StringBuilder builder = new StringBuilder();
        for (String arg : context.getArgs()) {
            builder.append(arg).append(" ");
        }
        if (PlayerInputManager.isWaitingForInput(player, InputType.COMMAND)) {
            PlayerInputManager.handleInput(player, builder.toString().trim());
        }
    }

    @Override
    public List<String> onTabComplete(CommandContext context) {
        return PlayerInputManager.handleInput(context.getPlayer(), context.getArgs());
    }

}
